package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CotegoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "分类相关接口")
public class CategoryController {
    @Autowired
    private CotegoryService categoryService;
    @ApiOperation("新增分类")
    @PostMapping
    public Result save(@RequestBody CategoryDTO categoryDTO){
        log.info("新增分类，分类信息：{}", categoryDTO);
        categoryService.save(categoryDTO);
        return Result.success();
    }
    @ApiOperation("分页查询分类信息")
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分页查询分类信息，参数为：{}", categoryPageQueryDTO);
         PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
         return Result.success(pageResult);

    }
    @ApiOperation("修改状态分类")
    @PostMapping("/status/{status}")
     public  Result startOrStop(@PathVariable Integer status,Long id){
        log.info("启用禁用员工账号：{},员工id：{}", status, id);
        categoryService.startOrStop(status, id);
         return Result.success();
    }
    @ApiOperation("修改分类信息")
    @PutMapping
    public Result upDate(@RequestBody CategoryDTO categoryDTO) {
        log.info("修改分类信息：{}", categoryDTO);
        categoryService.update(categoryDTO);
        return Result.success();
    }
    @ApiOperation("删除分类信息")
    @DeleteMapping
    public Result deleteById(List<Long> ids) {
        log.info("删除分类信息：{}", ids);
        categoryService.deleteById(ids);
        return Result.success();
    }
    @GetMapping("/list")
    public Result<List<Category>> list(Integer type) {
        log.info("根据类型查询分类：{}", type);
        List<Category> list = categoryService.list(type);
        return Result.success(list);
    }

}
